/*                          UX-Framework                               
 *                                                                 
 *  iZE Co.,Ltd. Copyright 2009 All rights reserved.          
 *  This file is distributed under the terms of the GNU Lesser 
 *  General Public License, described in file LICENSE.                                     
 */
package jp.ize.ux.components.themes.basic;

// {{{ imports
import jp.ize.ux.components.UXResource;
import jp.ize.ux.components.UXWindow;
import jp.ize.ux.components.UXComponentResource;
import jp.ize.ux.geom.UXSize;
import flash.display.MovieClip;
import flash.display.GradientType;
import flash.geom.Matrix;
// }}}
// {{{ class UXWindowResource
/** 
 * UXWindowResource クラス<br>
 * コンポーネントの描画に利用されるリソース情報です。<br>
 *
 * @author		iZE Co., Ltd.<br>
 * @version		$Id: UXButton.hx 20 2009-02-04 08:23:19Z yimai.v $<br>
 */
class UXWindowResource extends UXComponentResource
{
	// {{{ properties
	// {{{ public var st(default, default) : UXWindowState;
	/**
	 * UXWindowState
	 */
	public var st(default, default) : UXWindowState;
	// }}}
	// {{{ public var frame(default, default) : UXComponentResource
	/**
	 * ウィンドウの枠
	 */
	public var frame(default, default) : UXComponentResource;
	// }}}
	// {{{ public var background(default, default) : UXComponentResource
	/**
	 * ウィンドウの背景となるコンポーネントです。
	 */
	public var background(default, default) : UXComponentResource;
	// }}}
	// {{{ public var closeButton( default, default ) : UXComponentResource;
	/**
	 * 閉じるボタンのためのリソースです。
	 */
	public var closeButton( default, default ) : UXComponentResource;
	// }}}
	// {{{ public var titleBar( default, default ) : UXComponentResource
	/**
	 * タイトルバーに適用されるリソースです。
	 */
	public var titleBar( default, default ) : UXComponentResource;
	// }}}
	// {{{ public var icon( default, default ) : UXComponentResource
	/**
	 * タイトルバーに表示される小さいアイコンです。
	 */
	public var icon( default, default ) : UXComponentResource;
	// }}}
	// }}}
	// {{{ public function new( s:UXWindowState, ?res:Dynamic ) : Void
	/**
	* コンストラクタ
	*/
	public function new( s:UXWindowState, ?res:Dynamic ) : Void
	{
		super(res);
		var me = this;
		st = s;
		// {{{ frame
		frame = new UXComponentResource( new MovieClip() );
		// {{{ normal
		frame.setNormal(Draw(function(mc:MovieClip){
			var st = me.st;
			var g = mc.graphics;
			var delta = 5;
			g.clear();
			g.lineStyle( 10, 0x666666, 0.0 );
			g.drawRoundRect( 0, 0, st.size.width-delta, st.size.height-delta, st.cornerRadius );
			g.endFill();
		}));
		// }}}
		// {{{ focused
		frame.setFocused(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ highlighted
		frame.setHighlighted(Draw(function(mc:MovieClip){
			var st = me.st;
			var g = mc.graphics;
			var delta = 5;
			g.clear();
			g.lineStyle( 10, 0x666666, 0.0 );
			g.drawRoundRect( 0, 0, st.size.width-delta, st.size.height-delta, st.cornerRadius );
			g.endFill();
		}));
		// }}}
		// {{{ pressed
		frame.setPressed(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ disabled
		frame.setDisabled(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ selected
		frame.setSelected(Draw(function(mc:MovieClip){
		}));
		// }}}
		frame.normal();
		// }}}
		// {{{ background
		background = new UXComponentResource( new MovieClip() );
		// {{{ normal
		background.setNormal(Draw(function(mc:MovieClip){
			var st = me.st;
			var g = mc.graphics;
			var delta = 5;
			g.clear();
			g.lineStyle( 1.0, 0x999999, 0.3 );
			g.beginFill( 0x999999, 0.5 );
			g.drawRoundRect( delta, delta, st.size.width-delta, st.size.height-delta, st.cornerRadius );
			g.endFill();
			g.lineStyle( 1.0, 0x666666 );
			g.beginFill( 0xFFFFFF );
			g.drawRoundRect( 0, 0, st.size.width-delta, st.size.height-delta, st.cornerRadius );
			g.endFill();
		}));
		// }}}
		// {{{ focused
		background.setFocused(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ highlighted
		background.setHighlighted(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ pressed
		background.setPressed(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ disabled
		background.setDisabled(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ selected
		background.setSelected(Draw(function(mc:MovieClip){
		}));
		// }}}
		background.normal();
		// }}}
		// {{{ titleBar
		titleBar = new UXComponentResource( new MovieClip() );
		// {{{ normal
		titleBar.setNormal(Draw(function(mc:MovieClip){
			var st = me.st;
			var g = mc.graphics;
			var delta = 5;
			g.clear();

			var colors:Array<UInt> = [ 0xFFFFFF, 0xDDDDDD ];
			var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
			var ratios:Array<UInt> = [ 0, 255 ];
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox( st.size.width-delta, st.headerHeight, Math.PI/2, 0, 0 );


			g.lineStyle( 0.0, 0x666666, 0.5 );
			//g.beginFill( 0xEEEEEE );
			g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
			g.drawRoundRect( 0, 0, st.size.width-delta, st.headerHeight, st.cornerRadius );
			g.endFill();
			g.lineStyle( 0.0, 0x666666, 0.0 );
			//g.beginFill( 0xEEEEEE );
			g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
			g.drawRect( 0, st.cornerRadius, st.size.width-delta, st.headerHeight-st.cornerRadius );
			g.endFill();
			g.lineStyle( 0.0, 0x666666, 0.5 );
			g.moveTo( 0, st.cornerRadius );
			g.lineTo( 0, st.headerHeight );
			g.moveTo( 0, st.headerHeight );
			g.lineTo( st.size.width-delta, st.headerHeight );
			g.moveTo( st.size.width-delta, st.cornerRadius );
			g.lineTo( st.size.width-delta, st.headerHeight );
		}));
		// }}}
		// {{{ focused
		titleBar.setFocused(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ highlighted
		titleBar.setHighlighted(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ pressed
		titleBar.setPressed(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ disabled
		titleBar.setDisabled(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ selected
		titleBar.setSelected(Draw(function(mc:MovieClip){
		}));
		// }}}
		titleBar.normal();
		// }}}
		// {{{ closeButton
		var delta = 5;
		closeButton = new UXComponentResource( new MovieClip() );
		// {{{ normal
		closeButton.setNormal(Draw(function(mc:MovieClip){
			var st = me.st;
			var g = mc.graphics;
			var tw = st.headerHeight-delta*2;
			var th = st.headerHeight-delta*2;
			g.clear();

			var colors:Array<UInt> = [ 0xD8D8D8, 0xB8B8B8 ];
			var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
			var ratios:Array<UInt> = [ 0, 255 ];
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox( tw, th, Math.PI/2, 0, 0 );

			g.lineStyle( 0.0, 0x999999 );
			g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
			g.drawRoundRect( 0, 0, tw, th, 5 );
			g.endFill();
			g.lineStyle( 3.0, 0xFFFFFF );
			g.moveTo( 5, 5 );
			g.lineTo( tw-5, th-5 );
			g.moveTo( tw-5, 5 );
			g.lineTo( 5, th-5 );
			me.closeButton.x = st.size.width-st.headerHeight-delta/2;
			me.closeButton.y = delta;
		}));
		// }}}
		// {{{ focused
		closeButton.setFocused(Draw(function(mc:MovieClip){
		}));
		// }}}
		// {{{ highlighted
		closeButton.setHighlighted(Draw(function(mc:MovieClip){
			var st = me.st;
			var g = mc.graphics;
			var tw = st.headerHeight-delta*2;
			var th = st.headerHeight-delta*2;
			g.clear();

			var colors:Array<UInt> = [ 0xFE96A9, 0xFF0000 ];
			var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
			var ratios:Array<UInt> = [ 0, 255 ];
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox( tw, th, Math.PI/2, 0, 0 );

			g.lineStyle( 0.0, 0x999999 );
			g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
			g.drawRoundRect( 0, 0, tw, th, 5 );
			g.endFill();
			g.lineStyle( 3.0, 0xFFFFFF );
			g.moveTo( 5, 5 );
			g.lineTo( tw-5, th-5 );
			g.moveTo( tw-5, 5 );
			g.lineTo( 5, th-5 );
		}));
		// }}}
		// {{{ pressed
		closeButton.setPressed(Draw(function(mc:MovieClip){
			var st = me.st;
			var g = mc.graphics;
			var tw = st.headerHeight-delta*2;
			var th = st.headerHeight-delta*2;
			g.clear();

			var colors:Array<UInt> = [ 0xBE0101, 0xBE0101 ];
			var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
			var ratios:Array<UInt> = [ 0, 255 ];
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox( tw, th, Math.PI/2, 0, 0 );

			g.lineStyle( 0.0, 0x666666 );
			g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
			g.drawRoundRect( 0, 0, tw, th, 5 );
			g.endFill();
			g.lineStyle( 3.0, 0xCCCCCC );
			g.moveTo( 5, 5 );
			g.lineTo( tw-5, th-5 );
			g.moveTo( tw-5, 5 );
			g.lineTo( 5, th-5 );
		}));
		// }}}
		// {{{ disabled
		closeButton.setDisabled(Draw(function(mc:MovieClip){
			me.closeButton.pressed();
		}));
		// }}}
		// {{{ selected
		closeButton.setSelected(Draw(function(mc:MovieClip){
		}));
		// }}}
		closeButton.normal();
		// }}}
	}

	// }}}
}
// }}}
